/*

    This file is part of Hometree.

    Hometree is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Hometree is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Hometree.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2011,2012 Roman Held

*/
#ifndef TREEMODEL_H
#define TREEMODEL_H

/*===========================================================================*\
**      Include Dateien
\*===========================================================================*/
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>
#include <QTimer>
#include <QMenu>
#include "treeitem.h"

class QMimeData;
class HtrMonitor;

/*===========================================================================*\
**      Deklaration Klasse "TreeModel"
\*===========================================================================*/
class TreeModel : public QAbstractItemModel
{
  Q_OBJECT
  public:
    TreeModel(HtrMonitor *monitor, QObject *parent = NULL, QWidget *parentWidget = NULL);
    virtual ~TreeModel();

    virtual QVariant data(const QModelIndex &index, int role) const;
    virtual bool     setData(const QModelIndex &index, const QVariant &value, int role);

    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
    virtual QVariant headerData(int section, Qt::Orientation orientation,
                      int role = Qt::DisplayRole) const;
    virtual QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
    QModelIndex         index(const QString &path) const;

    virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
    virtual bool       dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
    virtual QStringList mimeTypes() const;

    virtual QModelIndex parent(const QModelIndex &index) const;
    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;

    const TreeItem *itemAt(const QModelIndex &index) const;
    void reset();

    void deleteItem(const QModelIndex &index);

 private slots:
    void createUrl(const QString &url, qint32 type);
    void removeUrl(const QString &url);
    void urlIsHot(const QString &url);
    void itemChanged(TreeItem *item);

 private:
    void             initRootItems();
    void             initScriptItems();
    QList<TreeItem*> itemsByPath(const QString &path);

    QStringList getDbFpgDirs()    const;
 
    TreeItem   *mRootItem;
    HtrMonitor *mMonitor;
    QTimer      mAnimationTimer;
};

#endif
